//
//  UIBarButtonItem+Extension.swift
//  Swift_Weibo_HLW
//
//  Created by huanglinwang on 16/9/19.
//  Copyright © 2016年 Linwang. All rights reserved.
//

import UIKit
//给UIBarButtonItem扩展一个便利构造函数
extension UIBarButtonItem {
    
    convenience init(title :String, imageName: String? = nil, target: Any? ,action: Selector){
        //self调用其他构造函数
        self.init()
        
        let button = UIButton()
        
        
        if imageName != nil {
            button.setImage(UIImage(named: imageName!), for: .normal)
            
        }
        button.addTarget(target, action: action, for: .touchUpInside)
        
        
        button.setTitle(title, for: .normal)
        //设置文字颜色
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.setTitleColor(UIColor.orange, for: .highlighted)
        //设置字体大小
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        button.sizeToFit()
        
        customView = button
    }
    
}
